package com.example.demo.mapper;

import com.example.demo.pojo.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    List<ShoppingCart> list(ShoppingCart shoppingCart);

    @Insert("insert into shopping_cart (name,image,user_id,goods_id,category,description,number,amount,create_time)" +
            "VALUES " +
            "(#{name},#{image},#{userId},#{goodsId},#{category},#{description},#{number},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    @Update("update shopping_cart set number=#{number} where id = #{id}")
    void updateNumberById(ShoppingCart cart);

    @Delete("delete from shopping_cart where id=#{id}")
    void deleteById(ShoppingCart cart);

    @Delete("delete from shopping_cart where user_id=#{userId}")
    void cleanShoppingCart(Long userId);

    @Select("select * from shopping_cart where id = #{id}")
    ShoppingCart getById(Long id);

    @Update("update shopping_cart set is_select=#{isSelect} where id=#{id}")
    void updateIsSelectById(ShoppingCart shoppingCart);

    @Select("select * from shopping_cart where user_id=#{userId} and is_select=1")
    List<ShoppingCart> getAllSelected(Long userId);

    @Delete("delete from shopping_cart where user_id=#{userId} and is_select=1")
    void deleteSelectedByUserId(Long userId);
}
